package com.sky.controller.admin;

import com.sky.dto.CategoryPageQueryDTO;
import com.sky.entity.Category;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.CategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 分类管理
 *
 * @Author mr.chen
 * @Date 2025/5/18 15:09
 */
@RestController
@RequestMapping("/admin/category")
@Api(tags = "分类管理")
public class CategoryController {

    @Autowired
    private CategoryService categoryService;

    /**
     * 分页查询
     * @param dto
     * @return
     */
    @GetMapping("/page")
    @ApiOperation("分页查询")
    public Result<PageResult> page(@ApiParam(value = "分页查询实体类",required = true)
                                       CategoryPageQueryDTO dto){
     return Result.success(categoryService.page(dto));
    }

    /**
     * 根据类型查询分类
     * @param type
     * @return
     */
    @GetMapping("/list")
    @ApiOperation("分页查询")
    public Result<List<Category>> list(@ApiParam(value = "根据type查询",required = true)
                                   @RequestParam("type") Integer type){
        return Result.success(categoryService.list(type));
    }

    /**
     * 根据id删除分类
     * @param id
     * @return
     */
    @DeleteMapping
    @ApiOperation("根据id删除分类")
    public Result<String> delete(@ApiParam(value = "根据分类id删除",required = true)@RequestParam("id") Integer id){
        categoryService.delete(id);
        return Result.success();
    }

    /**
     * 修改分类
     * @param dto
     * @return
     */
    @PutMapping
    @ApiOperation("修改分类")
    public Result<String> update(@ApiParam(value = "分类管理实体类",required = true)@RequestBody Category dto){
        categoryService.update(dto);
        return Result.success();
    }

    /**
     * 根据id修改状态
     * @param status
     * @param id
     * @return
     */
    @ApiOperation("根据id修改状态")
    @PostMapping("/status/{status}")
    public Result<String> updateStatus(@ApiParam(value = "分类id",required = true)@PathVariable("status")Integer status, @RequestParam("id")Integer id){
        categoryService.updateStatus(status,id);
        return Result.success();
    }

    /**
     * 添加套餐分类或者菜品分类
     * @param dto
     * @return
     */
    @ApiOperation("添加套餐分类或者菜品分类")
    @PostMapping
    public  Result<String> add(@ApiParam(value = "添加套餐分类或者菜品分类,根据type可知类型",required = true)@RequestBody Category dto){
        categoryService.add(dto);
        return Result.success();
    }
}
